const state = {
    assignment: [],
    successAudio: false,
    failAudio: false,
    questionAudio: false,
    fireworkLottie: false,
    sucLottie: false,
    operated: false,
    fireworkCoord: {},
    reward: [],
}
const getters = {
    //获取所有任务
    getAssignment(state) {
        return state.assignment
    },
    //问题音效是否播放
    getQuestionAudio(state) {
        return state.questionAudio
    },
    //烟花动画是否播放
    getFireworkLottie(state) {
        return state.fireworkLottie
    },
    //成功动画是否播放
    getSucLottie(state) {
        return state.sucLottie
    },
    //烟花动画初始化位置
    getFireworkCoord(state) {
        return state.fireworkCoord
    },
    getOperated(state) {
        return state.operated
    },
    //获取奖励池
    getReward(state) {
        return state.reward
    }
}
const mutations = {
    //初始化任务
    setAssignment(state, param) {
        state.assignment = param
    },
    //随机每一页的任务
    setPageAssignment(state,{questionIndex,param}){
      state.assignment[questionIndex] = param
    },
    //更新任务完成
    updateAssignmentFinish(state,  {questionIndex,param}) {
        state.assignment[questionIndex][param].isFinish = true
        state.assignment[questionIndex][param].operated = true
    },
    //删除该问题
    deleteAssignment(state, {questionIndex,param}) {
        state.assignment[questionIndex].splice(param,1)
    },
    //用户是否操作
    updateOperated(state, {questionIndex,param}) {
        state.assignment[questionIndex][param].operated = true
    },
    //播放问题声音
    setQuestionAudio(state) {
        state.questionAudio = true
    },
    palyQuestionAudio(state) {
        state.questionAudio = true
    },
    //初始化烟花位置并且播放
    setFireworkPlay(state, param) {
        state.fireworkCoord = param
        state.fireworkLottie = true
    },
    //播放成功动画
    setSucLottiePlay(state, ) {
        state.sucLottie = true
    },
    //   加入奖励池
    insertReward(state, param) {
        state.reward.push(param)
    },
    //    清空奖励池
    deleteReward(state) {
        if (state.reward.length > 0) {
            state.reward.splice(0, state.reward.length)
        }
    }
}
const actions = {
    setAssignment({ commit }, param) {
        commit("setAssignment", param)
    },
    setPageAssignment({commit},param){
      commit('setPageAssignment',param)
    },
    updateAssignmentFinish({ commit }, param) {
        commit("updateAssignmentFinish", param)
    },
    deleteAssignment({commit}, param) {
      commit("deleteAssignment", param)
    },
    setFireworkPlay({ commit }, param) {
        setTimeout(() => {
            state.fireworkLottie = false
            state.fireworkCoord = {}
        }, 2000)
        commit("setFireworkPlay", param)
    },
    updateOperated({ commit }, param) {
        commit("updateOperated", param)
    },
    setSucLottiePlay({ commit }) {
        setTimeout(() => { state.sucLottie = false }, 5000)
        commit("setSucLottiePlay")
    },
    setQuestionAudio({ commit }) {
        setTimeout(() => { state.questionAudio = false }, 1000)
        commit("setQuestionAudio")
    },
    insertReward({
                     commit
                 }, param) {
        commit("insertReward", param)
    },
    deleteReward({ commit }) {
        commit("deleteReward")
    }
}
export default {
    namespaced: true,//用于在全局引用此文件里的方法时标识这一个的文件名
    state,
    getters,
    mutations,
    actions
}
